package com.example.yuekao.model;

import com.example.mvp.Model.BaseModel;
import com.example.mvp.callback.BaseModelCallBack;
import com.example.mylibrary.client.HttpClient;
import com.example.yuekao.HttpCallBack.HttpCallBack;
import com.example.yuekao.bean.Bean;
import com.example.yuekao.bean.Demo;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.trello.rxlifecycle2.LifecycleProvider;

import java.util.List;

public class MianModel implements BaseModel {

    public void getData(BaseModelCallBack mainCallBack, LifecycleProvider lifecycleProvider){
        new HttpClient.Buidler()
                .setBaseUrl("https://api.zhuge.com/home/")
                .setApiUrl("v1/Appindex/showBanner")
                .setLifecycleProvider(lifecycleProvider)
              //  .addParamser("cityid",1)

                .post()
                .build()
                .excute(new HttpCallBack<List<Demo.ListBean>>() {
                    @Override
                    protected void error(String error, int code) {
                            mainCallBack.onerror(error,code);
                    }

                    @Override
                    protected void onSucess(List<Demo.ListBean> datasBeans) {
                        mainCallBack.onsucess(datasBeans);
                    }

                    @Override
                    public List<Demo.ListBean> convert(JsonElement jsonElement) {
                        Demo demo = new Gson().fromJson(jsonElement, Demo.class);
                        return demo.getList();
                    }
                });
    }

    public void getDatabean(BaseModelCallBack mainCallBack, LifecycleProvider lifecycleProvider){
        new HttpClient.Buidler()
                .setBaseUrl("https://api.zhuge.com/")
                .setApiUrl("home/v1/Appindex/showTopic")
                .setLifecycleProvider(lifecycleProvider)
               // .addParamser("cityid",1)
                .post()
                .build()
                .excute(new HttpCallBack<List<Bean.ListBean>>() {
                    @Override
                    protected void error(String error, int code) {
                        mainCallBack.onerror(error,code);
                    }

                    @Override
                    protected void onSucess(List<Bean.ListBean> datasBeans) {
                        mainCallBack.onsuccess1(datasBeans);
                    }

                    @Override
                    public List<Bean.ListBean> convert(JsonElement jsonElement) {
                        Bean demo = new Gson().fromJson(jsonElement, Bean.class);
                        return demo.getList();
                    }
                });
    }
}

